/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.actions;

import com.myapp.bd.QueryBD;
import com.myapp.bean.Etudiant;
import com.myapp.forms.ConsulterFicheForm;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author manoa
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
public class ConsulterFicheAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws SQLException {

        ConsulterFicheForm cf = (ConsulterFicheForm) form;

        QueryBD queryBD = new QueryBD();
        // cas ou la personne clique sur creer stage dans le menu
        if (cf.getChoix()==null) {

            ArrayList listEtudiants = (ArrayList) queryBD.recupListeEtudiantParPromo(cf.getPromotion());
            request.setAttribute("listEtudiants", listEtudiants);
            return mapping.findForward("rechercheListeEtudiant");
            //cas ou la personne veut consulter une fiche dans le menu
        } else {
            Etudiant e;
            e = queryBD.recupInfoEtudiant(cf.getnCandidat());
            e.setPromotion(cf.getPromotion());
            request.setAttribute("etudiant", e);
            return mapping.findForward("afficheFiche");
        }



    }
}
